var homeAction = {
    init: function() {
        this.homeView = $("#homeView");
        console.log(this.homeView);
        if (this.homeView.hasClass('inited')) {
            this.refresh();
            return;
        }
        this.homeView.addClass('inited');
        console.log('home init');

        this.getData();
    },
    refresh: function() {
        console.log('home refresh');
        this.getData();
    },
    getData: function() {
        if (!localStorage.getItem("logintime")) return false;
        appXhr.POST('/index',loginAction.loginParams())
        .done(function(data){
        	if (data.code == '100') {
        	    homeAction.setVal(data.content);
        	} else if (data.code == '-1001') {
        	    F7.alert(data.message);
        	}
        });
        
    },
    setVal:function(data){
        $("#waitCnt").text(data.waitCnt);
        $("#sendCnt").text(data.sendCnt);
        $("#transCnt").text(data.transCnt);
        $("#finishCnt").text(data.finishCnt);

        if(data.unreadMsgCnt > 0) {
            $("#msgBtn").find(".new-msg-dot").addClass('on');
        }else{
            $("#msgBtn").find(".new-msg-dot").removelass('on');
        }
    }
};

module.exports = homeAction;
